home *** CD-ROM | disk | FTP | other *** search
- // GptCGM.cpp
- // copyright 1992 Pittsburgh Supercomputing Center
- #include <windows.h>
- #include "cgmio.h"
- #include "gpta.h"
-
- cgmObject::cgmObject(CgmWindowPt win, FileObjectPt fobj )
- {
- cgmWin = win;
- file = fobj;
- cgm =NULL;
- cgmMeta =NULL;
- IsIndexed = FALSE;
- curPic =NULL;
- lastPic =NULL;
- hMeta = NULL;
- PicNum = 1;
- Pictures = 0;
- DidFullMeta = FALSE;
- hCompBit = NULL;
- hMemDC = NULL;
- hOldBit = NULL;
-
- }
-
-
- cgmObject::~cgmObject(void)
- {
- ZapLastPic();
- delete cgm;
- //if (hMeta)DeleteMetaFile(hMeta);
- if (hMemDC)
- {
- SelectObject(hMemDC, hOldBit);
- DeleteDC(hMemDC);
- DeleteObject(hCompBit);
- }
- }
-
- BOOL cgmObject::NextPageExists(void)
- { if (!curPic) return FALSE;
- if ( curPic->next ) return TRUE;
- else
- {
- Pictures = PicNum;
- IsIndexed = TRUE;
- return FALSE;
- }
- }
- BOOL cgmObject::PrevPageExists(void)
- { if (curPic && curPic->prev ) return TRUE; else return FALSE; }
-
-
- void cgmObject::ZapLastPic()
- {
- if (lastPic) lastPic->setAside();
- if (hMeta) {DeleteMetaFile(hMeta); hMeta = NULL;}
-
- }
-
- void cgmObject::ReadCurPic() { if (curPic) curPic->readIn(); }
-
- // *** CgmObject::WriteMetaFile - Write Out Windows Metafile to Disk
- void cgmObject::WriteMetaFile(FileObjectPt FObjMeta)
- {
- // Put Metafile on disk
- char filename[150];
- strcpy(filename, FObjMeta->GetFileName() );
- HANDLE hNewMeta = CopyMetaFile(hMeta, filename);
- hMeta = hNewMeta;
- }
-
- // *** CgmObject::MakeClearText - generate clear text file
- void cgmObject::MakeClearText(FileObjectPt FObj)
- {
-
- cgmEndMetafile myEnd; // for convenience
- ClearOutputPt myOutput = new clearOutput("", FObj->GetHandle() );
- cgmMeta->cgmOut(myOutput);
- // force the end
- myEnd.cgmOut(myOutput);
- delete myOutput;
- }
-
- // *** cgmObject::IndexCgm()
- WORD cgmObject::IndexCgm()
- {
- CgmPicturePt Pic;
- if ( IsIndexed ) return Pictures;
- if (!cgmMeta) return 0;
- cgmMeta->makeIndex();
- for( Pictures = 1, Pic= cgmMeta->firstPic;Pic = Pic->next; Pictures++);
- IsIndexed = TRUE;
- return Pictures;
- }
-
- // *** cgmObject::GetPictureText()
- void cgmObject::GetPictureText(PSTR text, void **picture)
- {
- *text = 0;
- CgmPicturePt pic = (CgmPicturePt)*picture;
- if (!cgmMeta) { *picture = NULL; return; }
- if (!pic) pic = cgmMeta->firstPic;
- if (pic->name() ) strcpy( text, pic->name());
- *picture = pic->next;
- }
-
- // *** cgmObject::GetSel()
- BOOL cgmObject:: GetSel( void **picture)
- {
- BOOL WantIt = FALSE;
- CgmPicturePt pic = (CgmPicturePt)*picture;
- if (!cgmMeta || !IsIndexed)
- { *picture = NULL; return FALSE; }
- if (!pic) pic = cgmMeta->firstPic;
- if (pic->want()) WantIt = TRUE;
- *picture = pic->next;
- return WantIt;
- }
-
- // *** cgmObject::SetSel()
- void cgmObject:: SetSel(BOOL WantIt, void **picture)
- {
- CgmPicturePt pic = (CgmPicturePt)*picture;
- if (!cgmMeta )
- { *picture = NULL; return; }
- if (!pic) pic = cgmMeta->firstPic;
- pic->setWant(WantIt);
- *picture = pic->next;
- }
-
- // *** cgmObject::NextPage()
- BOOL cgmObject::NextPage()
- {
- if ( !NextPageExists() ) return FALSE;
- CgmPicturePt pic = curPic->next;
- curPic = pic;
- PicNum++;
- // Force Redraw
- return TRUE;
- }
- // *** cgmObject::NewPage()
- BOOL cgmObject::NewPage(WORD Page)
- {
- int i;
- for( i=1, curPic= cgmMeta->firstPic; i < Page;i++)
- curPic = curPic->next;
- PicNum = Page;
- return TRUE;
- }
-
- // *** cgmObject::PreviousPage()
- BOOL cgmObject::PreviousPage()
- {
- if ( !PrevPageExists() ) return FALSE;
- CgmPicturePt pic = curPic->prev;
- curPic = pic;
- PicNum--;
- // Force Redraw
- return TRUE;
- }
- // *** CgmObject::GplotInit - find metafile and get to first picture
- void cgmObject::GPlotInit( )
- {
- cgmMetafile *metafile;
- cgm = new cgmFile(file->GetFileName(),file->GetHandle());
- if (!cgm) return;
- if (!(cgmMeta = cgm->foundMetafile()))
- {
- myError("no metafile in", file->GetFileName(), 0); // exits
- delete cgm;
- cgm = NULL;
- return;
- }
- curPic = cgmMeta->firstPic;
- if (!curPic)
- {
- myError("no pictures in file", file->GetFileName(), 0); // exits
- delete cgm;
- cgm = NULL;
- return;
- }
- }
-